package com.itany.nmms.util;

import com.itany.nmms.exception.MD5ErrorException;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

/**
 * @author 石小俊
 */
public class MD5Util {
    public static String md5(String password){
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] b = md.digest(password.getBytes());
            return Base64.getEncoder().encodeToString(b);
        } catch (NoSuchAlgorithmException e) {
            throw new MD5ErrorException("MD5加密出错");
        }
    }
}
